package main

import (
	"fmt"
	"html/template"
	"net/http"
	"strings"
	"log"
)

func sayHelloName(w http.ResponseWriter, r *http.Request){
	r.ParseForm()
	fmt.Println(r.Form)
	fmt.Println("path",r.URL.Path)
	fmt.Println("scheme",r.URL.Scheme)
	fmt.Println(r.Form["url_long"])
	for k,v := range r.Form{
		fmt.Println("key:",k)
		fmt.Println("val:",strings.Join(v,""))
	}
	fmt.Fprintf(w,"你好，我TM什么都没写呢....")
}



func login(w http.ResponseWriter, r *http.Request){
	r.ParseForm()

		if r.Method == "GET" {
				t,_ := template.ParseFiles("login.gtpl")
				t.Execute(w,nil)
		}else{
			fmt.Println("username:",r.Form["username"])
			fmt.Println("password",r.Form["password"])
		}
}

func index(w http.ResponseWriter, r *http.Request){
	r.ParseForm()
	t,_ := template.ParseFiles("index.gtpl")
	t.Execute(w,nil)
}

func main() {
	http.HandleFunc("/",index)
	http.HandleFunc("/login",login)

	err := http.ListenAndServe(":80",nil)//设置监听端口
	if err != nil {
		log.Fatal("ListenAndServe:",err)
	}
}
